from django.db import models
from ckeditor.fields import RichTextField
from user.models import User

class Bbs(models.Model):
    title = models.CharField(max_length=100, verbose_name='题目')
    content = RichTextField()
    type = models.CharField(max_length=50)
    user = models.ForeignKey(User, on_delete=True)
    top = models.BooleanField(default=False)
    anonymous = models.BooleanField(default=False)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'bbs'

class Comment(models.Model):
    bbs = models.ForeignKey(Bbs, on_delete=True)
    user = models.ForeignKey(User, on_delete=True)
    content = RichTextField()
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'comments'

class Like(models.Model):
    user = models.ForeignKey(User, on_delete=True)
    owner_type = models.CharField(max_length=50)
    owner_id = models.IntegerField()
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'likes'
        index_together = ['owner_type', 'owner_id']